<!--
 * @Author: your name
 * @Date: 2021-01-06 17:15:46
 * @LastEditTime: 2021-01-07 10:53:29
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \solaxcloud\src\views\test\frame\historyData.vue
-->
<template>
    <div class="frame-historyData-main-box">
        <div class="search-box">
            <div class="search-box-sub">
                <span class="lable-text">{{$t('device.inverter.SN')}}</span>
                <el-input v-model="inverterSN" style="width:160px;" :placeholder="$t('pleaseInput')" :disabled="true"></el-input>
            </div>
            <div class="search-box-sub">
                <span class="lable-text">{{$t('devWifi.wifiSN')}}</span>
                <el-input v-model="wifiSN" style="width:160px;" :placeholder="$t('pleaseInput')" :disabled="true"></el-input>
            </div>
            <div class="search-box-sub">
                <el-date-picker
                v-model="endTimeBefore"
                type="date"
                :placeholder="$t('test.deviceTest.beginTime')"
                value-format='yyyy-MM-dd'
                :picker-options="pickerOptions"
                >
                </el-date-picker>
                -
                <el-date-picker
                v-model="endTimeAfter"
                type="date"
                :placeholder="$t('index.endTime')"
                value-format='yyyy-MM-dd'
                :picker-options="pickerOptions"
                >
                </el-date-picker>
            </div>
            <div class="search-box-sub">
                <el-button type="primary" @click='query'>{{$t('query')}}</el-button>
            </div>
        </div>
        <baseTable v-loading="loading"  row-key='sid' :data="dataRows" border  stripe @selection-change="handleSelectionChange($event)"  :column='column' :select='false'>
            <template #errorType='{data}'>
                <span>{{this.comm.return(dictCodes,data.errorType,'value','code')}}</span>
            </template>
        </baseTable>
        <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="current"
        :page-sizes="[10, 20, 30, 50]"
        :page-size="size"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total">
        </el-pagination>
    </div>
</template>

<script>
import baseTable from '../../../components/common/baseTable'
export default {
    components: {
        baseTable
    },
    props: {

    },
    data() {
        return {
            inverterSN:"",
            wifiSN:"",
            endTimeBefore:"",
            endTimeAfter:"",
            pickerOptions:{ //禁用今天之后的时间
                disabledDate(time) {
                    return time.getTime() > Date.now()
                }
            },
            size:10,
            current:1,
            total:1,
            loading:false,
            dataRows:[],
            dictCodes:[],
            column:[{
                title: this.$t('alarm.errorCode'),
                value: 'errorCode',
            },
            {
                title: this.$t('alarm.errorType'),
                value: 'errorType',
                slot: 'errorType'
            },
            {
                title: this.$t('test.deviceTest.historyAlarm.errorMsg'),
                value: 'errorMessage',
                slot: 'errorMessage',
            },{
                title: this.$t('test.deviceTest.historyAlarm.uploadTimeValue'),
                value: 'timeStringVal',
                slot: 'timeStringVal'
            }],
        };
    },
    computed: {

    },
    watch: {

    },
    created() {

    },
    mounted() {
        this.inverterSN = this.$route.query.inverterSN
        this.wifiSN = this.$route.query.wifiSN
        this.deviceTestGetReportPage()
    },
    methods: {
        async getDictionaryBatch(){
            let res = await this.API.getDictionaryBatch({
                dictCodes:`ALARM_TYPES`,
                lang:localStorage.getItem('lang') || 'zh_CN'
            })
            this.dictCodes = res.ALARM_TYPES
            // this.deviceTestGetStateChart()
        },
        async deviceTestGetReportPage(){
            this.loading = true
            let res = await this.API.deviceTestGetInverterAlarmPage({
                inverterSN:this.inverterSN,
                wifiSN:this.wifiSN,
                alarmTimeBefore:this.endTimeBefore,
                alarmTimeAfter:this.endTimeAfter,
                size:this.size,
                current:this.current,
            })
            this.loading = false
            this.dataRows = res.rows
            this.total = res.total
        },
        query(){
            this.current = 1
            this.deviceTestGetReportPage()
        },
        handleSizeChange(val) {
          this.size = val
          this.current = 1
          this.deviceTestGetReportPage()
        },
        handleCurrentChange(val) {
          this.current = val
          this.deviceTestGetReportPage()
        },
    },
};
</script>

<style  lang="less" scoped>

</style>
